package com.youyiwen.Service.impl;

import com.youyiwen.Bean.Reply;
import com.youyiwen.Bean.User;
import com.youyiwen.Mapper.ReplyMapper;
import com.youyiwen.Mapper.UserMapper;
import com.youyiwen.Service.ReplyService;
import com.youyiwen.dto.ReplyDTO;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author: zhaoyang
 * @Date: 2021/04/03
 */
@Service
public class ReplyServiceImpl implements ReplyService {

    @Autowired
    private ReplyMapper replyMapper;

    @Autowired
    private UserMapper userMapper;

    @Override
    public List<ReplyDTO> selectReplyListByPId(String id) {
        List<ReplyDTO> list = new ArrayList<>();
        List<Reply> replies = replyMapper.selectReplyListByPId(id);
        for (Reply reply : replies) {
            User user = userMapper.selectUserByName(reply.getUserName());
            ReplyDTO replyDTO = new ReplyDTO();
            BeanUtils.copyProperties(reply,replyDTO);
            replyDTO.setUser(user);
            list.add(replyDTO);
        }
        return list;
    }
}
